#include "Scene.h"
#include "ZhicheEntity.h"
#include "Camera.h"

bool Scene::s_isInitialized = false;
bool Scene::s_isRendering = false;

CList<Entity*> Scene::s_entities;

FBO* Scene::s_backFBO = nullptr;
FBO* Scene::s_frontFBO = nullptr;

void Scene::init(IGLProcLoader* procLoader) {
	GLState::init(procLoader);
	Camera::init();

	if (Proj::isKT() || IsEnv_PC) {
		/**@note use 2 FBOs for more stable FPS and less screen tearing(flickering) */
		s_frontFBO = GLState::createFBO();
		s_backFBO = GLState::createFBO();
	}

	switchRenderingStatus(true);

	s_isInitialized = true;

	LogI << "[RenderThread]>>>>>> running on self-defined render-thread(@" << std::this_thread::get_id() << ")";

	Cache::startLoadingZhicheAtNewThread(5000);// let other lines/targets show immediately
}

void Scene::renderZhiche(Entity* zhiche) {
	auto zhicheEntity = dynamic_cast<ZhicheEntity*>(zhiche);
	zhicheEntity->renderAsTexture(s_backFBO);
}